<template>
  <div class="ke">
    <div class="center">
      <left></left>
      <div class="right">
        <top></top>
        <div class="hei10"></div>
        <div class="powertop">
          <router-link class="powertopli powertopact" to="/finance/ke">可返利订单</router-link>
          <router-link class="powertopli " to="/finance/wait">待返利数据</router-link>
          <router-link class="powertopli " to="/finance/jilu">返利记录</router-link>
        </div>
        <div v-loading='loading' style="padding: 20px;">
          <div class="kflexc">
            <div style="width: 250px; margin-right: 20px;">
              <el-input v-model="all.source_id" placeholder="请输入外部订单号检索"></el-input>
            </div>
            <div style="width: 250px; margin-right: 20px;">
              <el-input v-model="all.mobile" placeholder="请输入生产号码"></el-input>
            </div>
            <el-button type="primary" round  style="margin-right: 20px;" @click="search()">搜索</el-button>
            <div class="kflex" style="margin-right: 20px;">
              <el-button type="danger" round @click="daochushow">导出待人工返利数据</el-button>
            </div>
            <div class="kflex">
              <el-button type="primary" plain round @click="goid('/finance/wait/daochu')">查看导出记录</el-button>
            </div>
          </div>
          <el-table :data="list" border style="width: 100%; margin: 20px 0;">
            <el-table-column align='center' prop='order_id' label="订单ID"></el-table-column>
            <el-table-column align='center' prop='fanli_mobile' label="生产号码"></el-table-column>
            <el-table-column align='center' prop='month' label="领取月份"></el-table-column>
            <el-table-column align='center' prop='page_name' label="商品名称"></el-table-column>
            <el-table-column align='center' prop='fanli_money' label="返利金额"></el-table-column>
            <el-table-column align='center' prop='name' label="登记人员"></el-table-column>
            <el-table-column align='center' prop='gstatus_name' label="可领状态"></el-table-column>
            <el-table-column align='center' prop='fanli_status' label="是否满足返利">
              <template slot-scope="scope">
                <span v-if="scope.row.fanli_status==-1">不满足</span>
                <span v-if="scope.row.fanli_status==1">满足</span>
              </template>
            </el-table-column>
            <el-table-column align='center' prop='over_time' label="是否补领">
              <template slot-scope="scope">
                <span v-if="scope.row.over_time==1">是</span>
                <span v-if="scope.row.over_time==0">否</span>
              </template>
            </el-table-column>
            <el-table-column align='center' prop='rebate_status_name' label="充值状态"></el-table-column>

            <el-table-column align='center' label="操作">
              <template slot-scope="scope">
                <el-button type="text" @click="shanchu(scope.row)">删除记录</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination style="text-align: right;" background layout="total,prev, pager, next" :current-page="all.page" @current-change="fanye" :page-size="all.page_size" :total="total"></el-pagination>
        </div>
      </div>
    </div>

    <el-dialog title="导出待人工返利数据" center :visible.sync="daochulog" :close-on-click-modal="false" width="600px">
      <el-radio v-model="radio" :label="0">导出全部待返利数据</el-radio>
      <el-radio v-model="radio" :label="1">导出补领数据</el-radio>
      <el-radio v-model="radio" :label="2">导出本月数据</el-radio>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" round @click="daochu">导出</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import axios from 'axios'
  import top from '@/components/top.vue'
  import left from '@/components/left.vue'
  import foot from '@/components/foot.vue'
  import moment from "moment";
  import XLSX from 'xlsx';
  import {
      read,utils
    } from 'xlsx'

  export default {
    components: {
      "left": left,
      "top": top,
      "foot": foot
    },
    name: "ke",
    data() {
      return {
        times:[],
        loading:false,
        list:"",
        all:{
          page:1,
          page_size:20
        },
        total:0,
        log:false,
        daochulog:false,
        radio:0
      }
    },
    created() {
      this.getlist()
    },
    mounted() {

    },
    methods: {
      shanchu:function(item){

        this.$confirm('确定要删除记录吗','提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          center:true
        }).then(() => {

          axios.post('/api/plan-market/fanli/log/del?gid='+item.gid)
            .then(response => {
              if (response.data.msg.code == 0) {
                this.$message.success('操作成功');
                this.getlist()
              } else {
                this.$message.error(response.data.msg.info);
              }
            })
        })
      },
      readExcel1(files) {
        return new Promise((res, rej) => {
          var that = this;
          if (files.length <= 0) {
            return;
          }
          if (!/\.(xls|xlsx)$/.test(files[0].name.toLowerCase())) {
            this.$Message.error('上传格式不正确，请上传xls或者xlsx格式');
            return;
          }
          const fileReader = new FileReader();
          fileReader.onload = (ev) => {
            try {
              const data = ev.target.result;
              const workbook = read(data, {
                type: 'binary'
              });
              // 取第一张表
              const wsname = workbook.SheetNames[0];
              // 生成json表格内容
              const ws = utils.sheet_to_json(workbook.Sheets[wsname]);
              console.log(ws);
              // 后续为自己对ws数据的处理
              res(ws)
            } catch (e) {
              return false;
              rej(e)
            }
          };
          fileReader.readAsBinaryString(files[0]);
        })

      },
      uploasd(file, fileList) {
        var that = this
        let files = {
          0: file
        }
        let data = []

        let ff = this.readExcel1(files);
        ff.then((res) => {
          res.forEach(item => {
            let obj = {
              created_at: item['订单创建时间'],
              source_id: item['订单号'],
              mobile: item['收货人电话'],
              name: item['收货人姓名'],
              pay_amount: item['实付款'],
              address: item['收货地址'],
              id_card_name: item['实名姓名'],
              id_card_num: item['身份证号'],
              sku: item['SKU编码'],
              shop_order_status:item['订单状态']
            }
            data.push(obj)
          })
        })
      },
      daochushow:function(){
        this.daochulog = true
      },
      //导出
      daochu: function() {

        axios.post('/api/plan-market/fanli/rebate/export',{type:this.radio})
          .then(response => {
            if (response.data.msg.code == 0) {
              this.goid('/finance/wait/daochu')
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      search: function() {
        this.all.page = 1
        this.getlist()
      },
      //翻页
      fanye: function(page) {
        this.loading = true
        this.all.page = page
        this.getlist()
      },
      //获取列表
      getlist: function() {
        axios.get(`/api/plan-market/fanli/log/list`,{params:this.all})
          .then(response => {
            if (response.data.msg.code == 0) {
              this.list = response.data.data.data
              this.total = response.data.data.total
              this.loading = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },

    }
  }
</script>

<style lang="scss" scoped>
  .ke {
    .powertop {
    	display: flex;
    	background:#f9f9f9;
    }
    .powertopli {
    	flex-basis: 180px;
    	line-height: 50px;
    	border-bottom: 3px #F9F9F9 solid;
    	color: #727272;
    	border-right: 1px #F9F9F9 solid;
    	font-size: 16px;
    	text-align: center;
    }
    .router-link-active {
    	background: #FFFFFF;
    	border-bottom: 3px #2974FF solid;
    }
    /deep/ .el-pagination.is-background .btn-prev:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .btn-prev{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active{ background-color: #2974FF;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
        color: #fff;
    }
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
        color: #2974FF;
    }
    /deep/ .el-pager li{ border-radius: 14px; background: rgba(255, 255, 255, 1); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .btn-prev{ border-radius: 14px; padding: 0 10px;}
    /deep/ .btn-next{ border-radius: 14px; padding: 0 10px;}

    /deep/ .el-table th{ background: rgb(246, 246, 246);}
    /deep/ .el-input__inner{ line-height: 36px; height: 36px; font-size: 12px; background: rgb(247, 248, 250);  border: 0;}
    /deep/ .el-date-editor .el-range-input{ background: rgb(247, 248, 250); }
    /deep/ .el-button{ padding: 11px 23px !important;}
    /deep/ .el-button--mini{ padding: 6px 15px !important;}
    /deep/ .el-button--danger {
        color: #FFF;
        background-color: #2974FF;
        border-color: #2974FF;
    }
    .team {
    	background: #F9F9F9;
    }
  }
</style>
